﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.WebAPI.Application.Command.UserCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.UserCommandHandler
{
    /// <summary>
    /// 新增人员
    /// </summary>
    public class AddUserCommandHandler : IRequestHandler<AddUserCommand, Results<int>>
    {
        private readonly IUserService _userService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userService"></param>
        public AddUserCommandHandler(IUserService userService)
        {
            _userService = userService;
        }
        /// <summary>
        /// 新增人员
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<int>> Handle(AddUserCommand request, CancellationToken cancellationToken)
        {
            var users = await _userService.AddUser(request.User);
            return Results<int>.DataResult(users);
        }
    }
}
